<?php
define('IN_WONDERSHARE', true);
//include("../inc/global.php");
require('../includes/init.php');
require('./classes/control/control_products_mobile.php');

	class Product
	{
		var $products_c;
		function __construct(){
			$this->products_c = new ProductsMobileControl();
		}
		
		    //商品管理
	function index()
	{
	 if($_GET['in_jax'] == 1)//修改
	 {
  		$field = 'm_product_delete';
		if($_GET['type']=='del')
		{
		    if (!empty($_GET['p_id'])&&!empty($field))
		    echo $this->products_c->change_info((int)$_GET['p_id'],$_GET['value'],$field,'one_update');
		}
	 }elseif($_GET['in_jax'] == 2)//得到商品信息
	 {
	   if(!empty($_GET['checkList']))
	   {
	  	$checkList = substr($_GET['checkList'], 0, (trim(strlen($_GET['checkList'])) - 1) );
	  	$this->products_c->change_info(0,$checkList,'id','more_update');
	   }
        if (!empty($_GET['p_id']))
        {
         echo  $this->products_c->get_product_id('ajax',$_GET['p_id'],0);
        }
	 }else{
	  $url_info = $products_info = array();
	  //分页处理
	  $type = !empty($_REQUEST['type'])?$_REQUEST['type']:0;
	  $page = 1;$page_size = 20;
	  if($type == 1)
	  {
	  	$page_size = 160;
	  }
      if (!empty($_REQUEST['page'])) {
	  $page = (int)$_REQUEST['page'];
      }
	  if($_POST['search'] || !empty($_REQUEST['url_page']))
	  {
	  	 $_SESSION['fage'] = $_SESSION['fage']==1?$_SESSION['fage']:0;
	  	 $pr_name	= !empty($_POST['pr_name']) ? $_POST['pr_name'] : urldecode($_GET['pr_name']);
	     $pr_name  = $pr_name == '输入产品名称'?'':$pr_name;

         $url_info = $this->products_c->get_url_info($page,'list_s',$page_size,$_REQUEST['cat_id'],
         $_REQUEST['is_delete'],$pr_name,$_REQUEST['tag'],$_REQUEST['is_emphasis']);
	  	 $products_info = $this->products_c->get_products_info('list_s',$url_info['page_info']['start'],$page_size
	  	 ,$_REQUEST['cat_id'],$_REQUEST['is_delete'],$pr_name,$_REQUEST['tag'],$_REQUEST['is_emphasis']);
	  	 
	  	 $GLOBALS['smarty']->assign('pr_name',   stripslashes($pr_name));
	     $GLOBALS['smarty']->assign('cat_select_s',   cat_list(0, $_REQUEST['cat_id'], true,0,true,'   WHERE c.cat_web = 1 AND c.cat_type = 2  '));
	  	 $GLOBALS['smarty']->assign('tag',   $_REQUEST['tag']);
	  	 $GLOBALS['smarty']->assign('is_emphasis',   $_REQUEST['is_emphasis']);
	  }else
	  {
	  	$url_info = $this->products_c->get_url_info($page,'list',$page_size);
	  	$products_info = $this->products_c->get_products_info('list',$url_info['page_info']['start'],$page_size);
	  }
	  
	  
	  if($type == 1)
	  {
	  $product_listdata = !empty($_REQUEST['product_list'])?explode(',',$_REQUEST['product_list']):array();
	  }else if($type == 2)
	  {
	  	$product_listdata = !empty($_REQUEST['product_list'])?$_REQUEST['product_list']:0;
	  }
	  $products_edit_id = !empty($_REQUEST['products_id'])?$_REQUEST['products_id']:0;//此id是根据产品页面编辑页来的
	  $GLOBALS['smarty']->assign('products_edit_id',$products_edit_id);
	  $GLOBALS['smarty']->assign('product_listdata',$product_listdata);
	  $GLOBALS['smarty']->assign('product_list',$_REQUEST['product_list']);
	  $GLOBALS['smarty']->assign('type',$type);
      $GLOBALS['smarty']->assign('page_url',   $url_info['page_url']);
      $GLOBALS['smarty']->assign('products_info',$products_info );
      $GLOBALS['smarty']->assign('total',   $url_info['page_info']['total']);
      $GLOBALS['smarty']->assign('cat_select',   cat_list(0, 0, true,0,true,'   WHERE c.cat_web = 1 AND c.cat_type = 2  '));
	  $GLOBALS['smarty']->display('product_m_list.htm'); 
	 }
	}
		
		/**************************************
	     * 查询所有未删除的公共产品信息并将数据传入和调用smarty模版
		 * @access  public
		 * @param  
		 *
		 * @return  array
	     **************************************/
/*		
		function productList()
		{
			$page = 1;
		      if (!empty($_REQUEST['page'])) {
			  $page = intval($_REQUEST['page']);
		      }
		    $url_info=$this->ControlProduct->getProductListPage($page);
			$rows=$this->ControlProduct->getProductList($url_info['page_info']['start'],15);
			$product_brand=$this->ControlProduct->product_brand();
			if($rows)
			{
				foreach ($rows as $key => $value)
				{
					if($value['product_state']==0)
					{
						$rows[$key]['product_state']='未发布';
					}
					else 
					{
						$rows[$key]['product_state']='发布';
					}
					if($value['product_is_recommend']==0)
					{
						$rows[$key]['product_is_recommend']='未推荐';
					}
					else 
					{
						$rows[$key]['product_is_recommend']='推荐';
					}
					$rows[$key]['product_add_time']=date('Y-m-d',$value['product_add_time']);
				}
			}
			$GLOBALS['smarty']->assign('page_url',   $url_info['page_url']);
		    $GLOBALS['smarty']->assign('total',   $url_info['page_info']['total']);
		    $GLOBALS['smarty']->assign('product_brand', $product_brand);
			$GLOBALS['smarty']->assign('productlist',$rows);
			$GLOBALS['smarty']->display('product_m_list.htm');
		}
		*/
		/**************************************
	     * 搜索查询符合条件的未删除的公共产品信息并将数据传入和调用smarty模版
		 * @access  public
		 * @param  
		 *
		 * @return  array
	     **************************************/
		
		
		function SearchProductList()
		{
			$page = 1;
		      if (!empty($_REQUEST['page'])) {
			  $page = intval($_REQUEST['page']);
		      } 
		    $product_brand=trim($_REQUEST['product_brand']);
		    $search_type=intval($_REQUEST['search_type']);
		    $search_key=trim($_REQUEST['search_key']);
		    $url_info=$this->ControlProduct->SearchProductListPage($page,$product_brand,$search_type,$search_key);
			$rows = $this->ControlProduct->SearchProductList($url_info['page_info']['start'],15,$product_brand,$search_type,$search_key);
			$product_brand=$this->ControlProduct->product_brand();
			if(!empty($rows))
			{
				foreach ($rows as $key=>$value)
				{
					if($value['product_state']==0)
					{
						$rows[$key]['product_state']='未发布';
					}
					else 
					{
						$rows[$key]['product_state']='发布';
					}
					if($value['product_is_recommend']==0)
					{
						$rows[$key]['product_is_recommend']='未推荐';
					}
					else 
					{
						$rows[$key]['product_is_recommend']='推荐';
					}
					$rows[$key]['product_add_time']=date('Y-m-d',$value['product_add_time']);
				}
			}
			$GLOBALS['smarty']->assign('page_url',   $url_info['page_url']);
		    $GLOBALS['smarty']->assign('total',   $url_info['page_info']['total']);
		    $GLOBALS['smarty']->assign('product_brand', $product_brand);
			$GLOBALS['smarty']->assign('productlist',$rows);
			$GLOBALS['smarty']->display('product_m_list.htm');
		}
		
	/**************************************
     * 根据获取的产品ID到CBS中查询对应公共产品的相关信息信息
	 * @access  public
	 * @param   int     $product_id
	 *
	 * @return  array
     **************************************/
		function GetCBSdata()
		{
			$product_cbsid = intval($_REQUEST['pcbs_id']);
			$form_action=trim($_REQUEST['form_action']);
			if(!$product_cbsid)
			{
				$product_data['message']='请输入正确的产品ID';
			}
			else
			{
				if($form_action=="./product.php?action=AddProduct")
				{
					$result=$this->ControlProduct->DecideCBSdata($product_cbsid);
					if(!is_null($result))
					{
						$product_data['message']='此产品数据已经存到公共产品表中，不能重复操作！';
						$product_data = json_encode($product_data);
						echo $product_data;die();
					}
				}
				$product_info=$this->ControlProduct->GetCBSdata($product_cbsid);
				if(!empty($product_info))
				{
//					/***********
//					 * 获取版本号
//					 ***********/
//					$sale_version=$this->ControlProduct->get_sale_version($product_info);
//					$product_data['sale_version']=$sale_version['version_name'];
//					/***********
//					 * 获取价格
//					 ***********/
//					$price=$this->ControlProduct->get_price($product_info);
//					$product_data['price']=$price['curr'];
//					$product_data['price_old']=$price['old'];
					/****************
					 * 获取what's new
					 ****************/
					$whatnew=$this->ControlProduct->getWhatNew($product_info);
					$product_data['whatnew']=$whatnew;
					
					$product_data['product_name']=$product_info['product_name'];
					$product_data['brand_name']=$product_info['brand_name'];
					$product_data['product_sn']=$product_info['product_num'];
					$product_data['message']='success';
				}
				else 
				{
					$product_data['message']='在CBS中查不到相关产品的信息';
				}
			}
			$product_data['form_action']=$form_action;
			$product_data = json_encode($product_data);
			echo $product_data;
		}
		
	/**************************************
     * 打开一个新的添加页面
	 * @access  public
	 * @param   
	 *
	 * @return  array
     **************************************/
		function AddNewProduct()
		{
			$actionurl="./product.php?action=AddProduct";
			$product=array('product_isfree'=>0,
						   'product_type'=>0,
						   'product_state'=>0,
						   'selected'=>0,
						   'product_is_recommend'=>0);
			$GLOBALS['smarty']->assign('product',$product);
			$GLOBALS['smarty']->assign('actionurl',$actionurl);
			$GLOBALS['smarty']->display('product_detail.htm');
		}
	/**************************************
     * 保存产品的信息
	 * @access  public
	 * @param   
	 *
	 * @return  array
     **************************************/
		function AddProduct()
		{
			$product_data=$_REQUEST['product'];
			$product_data['product_add_time']=time();
			$product_data['product_add_user']=$_SESSION['AName'];
			$manage_product_data=$this->ControlProduct->ManageProductdata($product_data);
			if($manage_product_data)
			{
				$ruselt=$this->ControlProduct->AddProductData($manage_product_data);
				if($ruselt)
				{
					$this->ControlProduct->AddProductPrice($manage_product_data['product_cbsid'],$ruselt);
					$this->ControlProduct->AddProductVersion($manage_product_data['product_cbsid'],$ruselt);
				}
			}
			$_SERVER['QUERY_STRING']='action=productList';
			$this->productList();
		}
		
	/**************************************
     * 在所有产品列表中选择对应产品
	 * @access  public
	 * @param   string   product_list  产品ID列表
	 *
	 * @return  array
     **************************************/
		
		function RecommProduct()
		{
			$product_listdata=trim($_REQUEST['product_list']);
			if(strlen($product_listdata)>0)
			{
				$productlistdata=explode(",",$product_listdata);
			}
			else 
			{
				$productlistdata=0;
			}
			
			$rows = $this->ControlProduct->getProductListOne();
			if($rows)
			{
				foreach ($rows as $key => $value)
				{
					if($value['product_state']==0)
					{
						$rows[$key]['product_state']='未发布';
					}
					else 
					{
						$rows[$key]['product_state']='发布';
					}
					if($value['product_is_recommend']==0)
					{
						$rows[$key]['product_is_recommend']='未推荐';
					}
					else 
					{
						$rows[$key]['product_is_recommend']='推荐';
					}
					$rows[$key]['product_add_time']=date('Y-m-d',$value['product_add_time']);
				}
			}
			
			$GLOBALS['smarty']->assign('productlist',$rows);
			$GLOBALS['smarty']->assign('product_listdata',$productlistdata);
			$GLOBALS['smarty']->display('product_recomm.htm');
		}
	
		
		/**************************************
	     * 根据产品ID查询对应公共产品的所有信息并将数据传入和调用smarty模版
		 * @access  public
		 * @param   int     $_REQUEST['p_id']
		 *
		 * @return  array
	     **************************************/
		function product_detail()
		{
			$product_id=$_REQUEST['p_id'];
			$rows = $this->ControlProduct->ProductDetail($product_id);
				
			$rows['product_add_time']=date('Y-m-d',$rows['product_add_time']);
			$actionurl="./product.php?action=EditProduct";
			$GLOBALS['smarty']->assign('actionurl',$actionurl);
			$GLOBALS['smarty']->assign('product',$rows);
			$GLOBALS['smarty']->display('product_detail.htm');
		}
		
		/**************************************
	     * 修改产品信息
		 * @access  public
		 * @param   array     $_REQUEST['product']
		 *
		 * @return  array
	     **************************************/
		
		function EditProduct()
		{
			$product_data=$_REQUEST['product'];
			$product_data['product_update_time']=time();
			$manage_product_data=$this->ControlProduct->ManageProductdata($product_data);
			if($manage_product_data)
			{
				$this->ControlProduct->EditProductData($manage_product_data);
			}
			$this->productList();
		}
		
		/**************************************
	     * 删除产品信息
		 * @access  public
		 * @param   array     $_REQUEST['product']
		 *
		 * @return  array
	     **************************************/
		
		function DelProduct()
		{
			$product_id=intval($_REQUEST['product_id']);
			if(!empty($product_id))
			{
				$type = $this->ControlProduct->DelProduct($product_id);
				echo $type;
			}
//			$this->productList();
		}
		
		
		/**************************************
	     * 发布产品信息
		 * @access  public
		 * @param   array     $_REQUEST['product']
		 *
		 * @return  array
	     **************************************/
		function StateProduct()
		{
			$product_id=intval($_REQUEST['product_id']);
			if($product_id)
			{
				$this->ControlProduct->StateProduct($product_id);
			}
			$this->productList();
		}
		
		/**************************************
	     * 取消发布产品信息
		 * @access  public
		 * @param   array     $_REQUEST['product']
		 *
		 * @return  array
	     **************************************/
		function CancelStateProduct()
		{
			$product_id=intval($_REQUEST['product_id']);
			if($product_id)
			{
				$this->ControlProduct->CancelStateProduct($product_id);
			}
			$this->productList();
		}
		
		/**************************************
	     * 推荐产品信息
		 * @access  public
		 * @param   array     $_REQUEST['product']
		 *
		 * @return  array
	     **************************************/
		function RecommendProduct()
		{
			$product_id=intval($_REQUEST['product_id']);
			if($product_id)
			{
				$this->ControlProduct->RecommendProduct($product_id);
			}
			$this->productList();
		}
		
		/**************************************
	     * 推荐产品信息
		 * @access  public
		 * @param   array     $_REQUEST['product']
		 *
		 * @return  array
	     **************************************/
		function CancelRecommendProduct()
		{
			$product_id=intval($_REQUEST['product_id']);
			if($product_id)
			{
				$this->ControlProduct->CancelRecommendProduct($product_id);
			}
			$this->productList();
		}
		
		/**************************************
	     * 产品价格信息管理
		 * @access  public
		 * @param   int     $_REQUEST['product_id']
		 *
		 * @return  array
	     **************************************/
		function ManagePrice($product_id="")
		{
			if($product_id)
			{
				$product_id=intval($product_id); 
			}
			else 
			{
				$product_id=intval($_REQUEST['product_id']);
			}	
			$page = 1;
		      if (!empty($_REQUEST['page'])) {
			  $page = intval($_REQUEST['page']);
		      }
	
			if($product_id)
			{
				$rows=$this->ControlProduct->ProductDetail($product_id);
				$url_info=$this->ControlProduct->ManagePrice($product_id,$page);
				$product_price = $this->ControlProduct->ManagePricePage($url_info['page_info']['start'],25,$product_id);
				$GLOBALS['smarty']->assign('page_url',   $url_info['page_url']);
		    	$GLOBALS['smarty']->assign('total',   $url_info['page_info']['total']);
				$GLOBALS['smarty']->assign('product_price',$product_price);
				$GLOBALS['smarty']->assign('prod',$rows);
				$GLOBALS['smarty']->display('product_price.htm');
			}
		}
		
		/**************************************
	     * 同步产品CBS价格信息
		 * @access  public
		 * @param   int     $product_id         产品id
		 * @param   int     $product_cbsid      cbs产品id
		 * @return  array
	     **************************************/
		 function sync_price_cbs($type = '',$product_id = 0,$product_cbsid = 0)
		 {
		 	if($type != 'all')
		 	{
			 	$product_cbsid=intval($_REQUEST['product_cbsid']);
				$product_id=intval($_REQUEST['product_id']);
		 	}
			$product_info=$this->ControlProduct->GetCBSdata($product_cbsid);
			$product_sn=$product_info['product_num'];
			$product_price=$product_info['price'];
			$result=$this->ControlProduct->sync_price_cbs($product_price,$product_id,$product_cbsid,$product_sn);
			$_SERVER['QUERY_STRING']='action=ManagePrice&product_id='.$product_id;
			$this->ManagePrice($product_id);
		 }
	/**************************************
	     * 同步产品CBS产品信息
		 * @access  public
		 * @param   int     $product_id         产品id
		 * @param   int     $product_cbsid      cbs产品id
		 * @return  array
	     **************************************/
		 function sync_product_name_cbs($type = '',$product_id = 0,$product_cbsid = 0)
		 {
		 	$info = array();
	
		 	if(!empty($product_cbsid))
		 	{
				$info = json_decode(file_get_contents('http://cbsapi.wondershare.cn/interface.php?m=cms_product&type=product_content&pids='.(int)$product_cbsid));
			    if(!empty($info->$product_cbsid) && !empty($product_id))//同步cbs的产品名称以及产品牌等。。
			    {
				    	$sql = 'UPDATE  product  SET product_name = "'.trim($info->$product_cbsid->product_name).'",product_brand = "'.trim($info->$product_cbsid->brand_name).'" 
				    	,product_sn = "'.trim($info->$product_cbsid->product_num).'"  WHERE product_id = '.(int)$product_id;
				 	    $GLOBALS['db']->query($sql);
	
			    }else if(empty($info->$product_cbsid) && !empty($product_id))//处理下架产品
			    {
			    	    $sql = 'UPDATE  product  SET is_shelves  = 1 WHERE product_id = '.(int)$product_id;
				 	    $GLOBALS['db']->query($sql);
			    }
		 	}
		 
		    unset($info);
		 }
		 /**************************************
	     * 同步全部cbs产品
		 * @access  public
		 * @return  array
	     **************************************/
		 function Sync_Product_All()
		 {
		 	$sql = "SELECT product_id,product_cbsid FROM product ";

		 	$result = $GLOBALS['db']->query($sql);
		 	while($row = $GLOBALS['db']->fetch_array($result))
		 	{
		 		if($row['product_id'] != 115){//837
				$this->sync_price_cbs('all',$row['product_id'],$row['product_cbsid']);
		 		$this->sync_version_cbs('all',$row['product_id'],$row['product_cbsid']);
		 		$this->sync_product_name_cbs('all',$row['product_id'],$row['product_cbsid']);
				}
		 	}
		 	
		 }
		 
		/**************************************
	     * 产品版本信息管理
		 * @access  public
		 * @param   int     $_REQUEST['product_id']
		 *
		 * @return  array
	     **************************************/
		function ManageVersion($product_id="")
		{
			if($product_id)
			{
				$product_id=intval($product_id); 
			}
			else 
			{
				$product_id=intval($_REQUEST['product_id']);
			}	
			$page = 1;
		      if (!empty($_REQUEST['page'])) {
			  $page = intval($_REQUEST['page']);
		      }
	
			if($product_id)
			{
				$rows=$this->ControlProduct->ProductDetail($product_id);
				$url_info=$this->ControlProduct->ManageVersion($product_id,$page);
				$product_version = $this->ControlProduct->ManageVersionPage($url_info['page_info']['start'],15,$product_id);
				$GLOBALS['smarty']->assign('product',$rows);
				$GLOBALS['smarty']->assign('page_url',   $url_info['page_url']);
		    	$GLOBALS['smarty']->assign('total',   $url_info['page_info']['total']);
				$GLOBALS['smarty']->assign('product_version',$product_version);
				$GLOBALS['smarty']->display('product_version.htm');
			}
		}
		
		/**************************************
	     * 同步产品CBS版本信息
		 * @access  public
		 * @param   int     $_REQUEST['product_id']
		 *
		 * @return  array
	     **************************************/
		function sync_version_cbs($type = '',$product_id = 0,$product_cbsid = 0)
		{
		    if($type != 'all')
		 	{
			 	$product_cbsid=intval($_REQUEST['product_cbsid']);
				$product_id=intval($_REQUEST['product_id']);
		 	}
	
			$product_info=$this->ControlProduct->GetCBSdata($product_cbsid);
			$product_sn=$product_info['product_num'];
			$product_version=$product_info['version'];
			$result=$this->ControlProduct->sync_version_cbs($product_version,$product_id,$product_cbsid,$product_sn);
			$_SERVER['QUERY_STRING']='action=ManageVersion&product_id='.$product_id;
			$this->ManageVersion($product_id);
		}
		
		
		/**************************************
	     * 产品的What's new 内容
		 * @access  public
		 * @param   int     $_REQUEST['product_id']
		 *
		 * @return  array
	     **************************************/
		function Version_new()
		{
			$product_id=intval($_REQUEST['product_id']);
			$version_id=intval($_REQUEST['version_id']);
			if($product_id)
			{
				$rows=$this->ControlProduct->ProductDetail($product_id);
				$product_version = $this->ControlProduct->Version_new($version_id);
				$product_version['whatisnew_content']= str_replace("\n","<br>",$product_version['whatisnew_content']);
				$GLOBALS['smarty']->assign('product',$rows);
				$GLOBALS['smarty']->assign('product_version',$product_version);
				$GLOBALS['smarty']->display('product_verdetail.htm');
			}
		}
		
		/**************************************
	     * 产品价格的详细信息
		 * @access  public
		 * @param   int     $_REQUEST['product_id']
		 * @param   int     $_REQUEST['id']
		 *
		 * @return  array
	     **************************************/
		function ProductPriceDetail()
		{
			$product_id=intval($_REQUEST['product_id']);
			$id=intval($_REQUEST['id']);
			if($product_id)
			{
				$rows=$this->ControlProduct->ProductDetail($product_id);
				$product_price=$this->ControlProduct->ProductPriceDetail($id);
				if($product_price['website_display']==0)
					{
						$product_price['website_display']='否';
					}
					else 
					{
						$product_price['website_display']='是';
					}
				$GLOBALS['smarty']->assign('product',$rows);
				$GLOBALS['smarty']->assign('price',$product_price);
				$GLOBALS['smarty']->display('product_price_detail.htm');
			}
		}
		
		
		/**************************************
	     * 修改产品价格的是否在网站显示
		 * @access  public
		 * @param   int     $_REQUEST['price_id']  价格表的ID
		 * @param   int     $_REQUEST['value']     是否显示 0，1
		 *
		 * @return  array
	     **************************************/
		function UpdataPriceProduct()
		{
			$price_id=intval($_REQUEST['price_id']);
			$price_value=intval($_REQUEST['value']);
			$this->ControlProduct->UpdataPriceProduct($price_id,$price_value);
		}
		
		/**************************************
	     * 修改产品的子价格的是否在网站显示
		 * @access  public
		 * @param   int     $_REQUEST['price_id']     价格表的ID
		 * @param   int     $_REQUEST['value']        是否显示 0，1
		 * @param   int     $_REQUEST['license_id']   license_id
		 * @param   int     $_REQUEST['product_id']   产品ID
		 *
		 * @return  array
	     **************************************/
		function UpdataSonPriceProduct()
		{
			$price_id=intval($_REQUEST['price_id']);
			$price_value=intval($_REQUEST['value']);
			$license_id=intval($_REQUEST['license_id']);
			$product_id=intval($_REQUEST['product_id']);
			$this->ControlProduct->UpdataSonPriceProduct($price_id,$price_value,$license_id,$product_id);
		}
		
		/**************************************
	     * 搜索查询符合条件的未删除的公共产品信息并将数据传入和调用smarty模版
		 * @access  public
		 * @param  
		 *
		 * @return  array
	     **************************************/
		
		function SearchProductListInDetail()
		{
		    $product_is_recommend=intval($_REQUEST['product_is_recommend']);
		    $product_state=intval($_REQUEST['product_state']);
		    $search_type=intval($_REQUEST['search_type']);
		    $search_key=trim($_REQUEST['search_key']);
		    $product_plat=trim($_REQUEST['product_plat']);
		    $display_type=trim($_REQUEST['display_type']);
		    $productlistdata=trim($_REQUEST['product_listdata']);
		    $product_id  = !empty($_REQUEST['product_id'])?$_REQUEST['product_id']:0;
			$rows = $this->ControlProduct->SearchProductListInDetail($product_is_recommend,$product_state,$search_type,$search_key,$product_plat,$product_id);
			if($rows)
			{
				foreach ($rows as $key => $value)
				{
					if($value['product_state']==0)
					{
						$rows[$key]['product_state']='未发布';
					}
					else 
					{
						$rows[$key]['product_state']='发布';
					}
					if($value['product_is_recommend']==0)
					{
						$rows[$key]['product_is_recommend']='未推荐';
					}
					else 
					{
						$rows[$key]['product_is_recommend']='推荐';
					}
					$rows[$key]['product_add_time']=date('Y-m-d',$value['product_add_time']);
				}
			}
			$GLOBALS['smarty']->assign('product_id',$product_id);
			$GLOBALS['smarty']->assign('product_listdata',$productlistdata);
			$GLOBALS['smarty']->assign('productlist',$rows);
			$GLOBALS['smarty']->assign('product_platform',$product_plat);
			if($display_type=='display_one')
			{
				$GLOBALS['smarty']->display('product_recomm.htm');
			}
			else 
			{
				$GLOBALS['smarty']->display('product_recomm_two.htm');
			}
		}
		
		/**************************************
     * 在所有产品列表中选择对应产品
	 * @access  public
	 * @param   string   product_list  产品ID列表
	 *
	 * @return  array
     **************************************/
		
		function RecommProductTwo()
		{
			$product_listdata=intval($_REQUEST['product_list']);
			$productlistdata=$product_listdata==0?0:$product_listdata;
			$product_platform  = !empty($_REQUEST['product_platform'])?$_REQUEST['product_platform']:'';
			$product_id  = !empty($_REQUEST['product_id'])?$_REQUEST['product_id']:0;
			$rows = $this->ControlProduct->getProductListOne($product_id,$product_platform,'product_edit');
		
			if($rows)
			{
				foreach ($rows as $key => $value)
				{
					if($value['product_state']==0)
					{
						$rows[$key]['product_state']='未发布';
					}
					else 
					{
						$rows[$key]['product_state']='发布';
					}
					if($value['product_is_recommend']==0)
					{
						$rows[$key]['product_is_recommend']='未推荐';
					}
					else 
					{
						$rows[$key]['product_is_recommend']='推荐';
					}
					$rows[$key]['product_add_time']=date('Y-m-d',$value['product_add_time']);
				}
			}
			
			$GLOBALS['smarty']->assign('productlist',$rows);
			$GLOBALS['smarty']->assign('product_id',$product_id);
			$GLOBALS['smarty']->assign('product_listdata',$productlistdata);
			$GLOBALS['smarty']->assign('product_platform',$product_platform);
			$GLOBALS['smarty']->display('product_recomm_two.htm');
		}
		
		function UpdataVersion()
		{
			$version_id=intval($_REQUEST['version_id']);
			$sale_type=intval($_REQUEST['value']);
			$this->ControlProduct->UpdataVersion($version_id,$sale_type);
		}
		
		function test()
		{
			$product_id=$_REQUEST['product_id'];
			$result=$this->ControlProduct->get_price($product_id);
			var_dump($result);
		}
		
	}
	
	
	
	$action    = $_REQUEST['action']; 
	$Product   = new Product;
	
	if(method_exists($Product, $action)) {
			$Product->$action();
	}else{
			$Product->index();
	}
?>
